<?php
/**
 * Interface zum Db_Connector
 *
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2013 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/lizenzbedingungen     New BSD License
 *
 * */


class Yapary_Db_Sql_TableCol
{
    private $tableName    = NULL;
    private $connection   = NULL;


    function __construct (MySQLi $_connection, $_tableName) {
        $this->connection = $_connection;
        $this->tableName  = $_tableName;
    }


    /**
     * Liefert die Anzahl an Spalten
     * @return int
     * */
    public function getCount () {
		return (int) count($this->getList());
    }


    /**
     * Liefert alle Spaltennamen als Array
     * @return Array
     * */
    public function getList () {
    	/* @var $resId mysqli_result */
		$resId = @$this->connection->query('SHOW COLUMNS FROM '.$this->tableName);
		if (gettype($resId) !== 'object') {
		    return NULL;
		    //trigger_error('FATAL ERROR in <b>'.__METHOD__.'</b> TMP data does not exist', E_USER_ERROR);
		}

		while ($result = @$resId->fetch_array()) {
			$arrResult[] = $result["Field"];
		}

	    return $arrResult;
    }


    /**
     * Gibt eine Instanz der TableColInfo-Klasse aus
     * @return Yapary_Db_ITableColInfo
     * */
    public function info ($_colName) {
        return new Yapary_Db_Sql_TableColInfo($this->connection, $this->tableName, $_colName);
    }

}


?>